<template>
  <div>
    <div
      style="font-size: 16px;font-weight: 500;color: #1D2129;margin-bottom: 16px;"
    >
      体育场地
    </div>
    <div style="display: flex; jiustify-content: space-between;">
      <div style="display: flex; width: 50%;">
        <img
          src="@/assets/img/Frame@2x (1).png"
          alt=""
          style="width: 32px;height: 32px; margin-right: 16px;18px;margin-top: 5px"
        />
        <div>
          <div style="font-size: 24px;color: #0F0F0F;">{{ placeSum }}</div>
          <div style="font-size: 12px;">体育场地数量</div>
        </div>
      </div>
      <div style="display: flex; width: 50%;">
        <img
          src="@/assets/img/Frame@2x (2).png"
          alt=""
          style="width: 32px;height: 32px; margin-right: 16px;18px;margin-top: 5px"
        />
        <div>
          <div style="font-size: 24px;color: #0F0F0F;">{{ acreageSum }}</div>
          <div style="font-size: 12px;">体育场地总面积/平方米</div>
        </div>
      </div>
    </div>
    <div id="Chart1" style="width:100%;height:198px"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { getPlaceData } from "@/api/statistics";
export default {
  data() {
    return {
      chartInstance: null,
      placeNameList: [],
      placeAcreageList: [],
      acreageSum: 0,
      placeSum: 0
    };
  },
  mounted() {
    this.datalist();
  },

  methods: {
    async datalist() {
      const res = await getPlaceData({ year: new Date().getFullYear() });
      if (res.data) {
        this.placeNameList = res.data.placeNameList;
        this.placeAcreageList = res.data.placeAcreageList;
        this.acreageSum = res.data.acreageSum;
        this.placeSum = res.data.placeSum;
      }
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("Chart1"));
      // 指定图表的配置项和数据
      var option;
      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data: this.placeNameList,
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ],
        series: [
          {
            name: "Direct",
            type: "bar",
            barWidth: "60%",
            data: this.placeAcreageList,
            itemStyle: {
              normal: {
                color: "#41B776"
              }
            }
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      // 监听父元素大小变化 刷新图表
      var ro = new ResizeObserver(entries => {
        for (let entry of entries) {
          const cr = entry.contentRect;
          myChart.resize();
        }
      });
      ro.observe(Chart);
    }
  }
};
</script>

<style scoped>
.dianidan {
  width: 7px;
  height: 7px;
  margin-right: 5px;
  margin-top: 3px;
}
</style>
